//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __CEVENT_H__
#define __CEVENT_H__

#include <elasys_server.h>
#include <interlocked.h>

class CEvent : public IEvent
{
// Interface functions
//
public:
    CARAPI_(PInterface) Probe(
        /* [in]  */ REIID riid);

    CARAPI_(UInt32)AddRef();

    CARAPI_(UInt32)Release();

    CARAPI Aggregate(
        /* [in]  */ AggregateType type,
        /* [in]  */ PInterface pObj);

    CARAPI GetDomain(
        /* [out] */ PInterface * ppObj);

    CARAPI Wait(
        /* [out] */ WaitResult * pResult,
        /* [out] */ EventState * pState);

    CARAPI TryWait(
        /* [in]  */ Millisecond32 msTimeout,
        /* [out] */ WaitResult * pResult,
        /* [out] */ EventState * pState);

    CARAPI Notify(
        /* [in ] */ EventState dwState = SIGNALED);

    CARAPI Clear();

public:
    static ECode New(
        /* [in] */ Boolean bManualReset,
        /* [in] */ EventState initialState,
        /* [out] */ IEvent ** ppEvent);

public:
    CEvent():m_hEvent(NULL){}
    virtual ~CEvent();

    ECode Constructor(
        /* [in] */ Boolean bManualReset,
        /* [in] */ EventState initialState);

private:
    PVoid  m_hEvent;

private:
    Interlocked m_cRef;
};

#endif  //__CEVENT_H__
